<?php
/**
 * 网站数据操作器
 *
 * @category     Shuxun Cms
 * @date         2015年11月18日
 * @author       Shuxun Team <kaiping.jiang@scshux.com>
 * @file         Site.php
 */
namespace  Scshux\Plugin;
use Scshux\AbstractPlugin;
use Scshux\Mvc\SModel;
use Scshux\Utils\Tree;
class Site extends  AbstractPlugin
{
	protected  $_siteConfig = null;

	/**
	 * 获取网站配置
	 */
	public function getSiteConfig()
	{
		if($this->_siteConfig == null){
			$siteConfigModel = new SModel('config');
			$siteID = $this->getCore()->getSiteID('site_id='.$siteID);
			$items = $siteConfigModel->query('site_id='.$siteID);
			$this->_siteConfig = new \stdClass();
			foreach ($items as $item)
			{
				$this->_siteConfig->{$item->code}=$item->value;
			}
		}
		return $this->_siteConfig;
	}


	/**
	 * 获取网站菜单
	 */
	public  function getSiteMenus()
	{
		$menusModel = new SModel('menus');
		$menusModel->setFetchMode(\PDO::FETCH_ASSOC);
		$siteID = $this->getCore()->getSiteID('site_id='.$siteID);
		$menus = $menusModel->query('site_id='.$siteID,'*','sort desc ,id','asc');
		$treeObj = new Tree($menus);
		return $treeObj->getTree();
	}

}